package com.zmn.plat.admin.controller.service.item.config;

import java.util.List;
import java.util.Objects;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.zmn.plat.model.entity.category.BaseCategory;
import com.zmn.plat.model.entity.servcategory.ServCategory;
import com.zmn.plat.model.entity.service.group.ServiceGroup;
import com.zmn.plat.model.entity.service.item.ServiceItem;
import com.zmn.plat.model.entity.service.tariff.ServiceTariff;
import com.zmn.plat.model.vo.service.item.config.ServiceItemTimeConfigVO;

/**
 * @author tanbiao
 * @description
 * @modifier
 * @since 2020/7/30 15:19
 **/
@RequestMapping("/service/item/timeConfig/")
@Controller
public class ServiceItemTimeConfigListController extends ServiceItemTimeConfigBaseController {
    /**
     * 详情
     *
     * @param itemId
     * @author tanbiao
     * @since 2019-11-21 18:57:24
     */
    @RequestMapping("detail")
    @RequiresPermissions("/service/item/timeConfig/detail.action")
    public ModelAndView detail(@RequestParam(value = "itemId", defaultValue = "0") Integer itemId) {
        ModelAndView mav = new ModelAndView("service/item/config/detail");
        List<ServiceItemTimeConfigVO> itemConfigs = faultItemTimeConfigBService.listByItemId(itemId);
        ServiceItem item = faultItemService.findByKey(itemId);
        ServiceGroup group = new ServiceGroup();
        ServCategory servCategory = new ServCategory();
        BaseCategory baseCategory = new BaseCategory();
        ServiceTariff faultTariff = new ServiceTariff();
        if (!Objects.isNull(item)) {
            group = faultGroupService.findByKey(item.getGroupId());
            servCategory = servCategoryService.findByKey(group.getServCategId());
            baseCategory = baseCategoryService.findByKey(group.getCategOneId());
            faultTariff = faultTariffService.findByKey(item.getTariffId());
        }
        mav.addObject("faultItem", item);
        mav.addObject("flag", 3);
        mav.addObject("servCategory", servCategory);
        mav.addObject("baseCategory", baseCategory);
        mav.addObject("faultTariff", faultTariff);
        mav.addObject("faultGroup", group);
        mav.addObject("timeGroups", itemConfigs);
        return mav;
    }
}
